﻿using HynuIOTA.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace HynuIOTA.Web
{
    /// <summary>
    /// ValidateCode 的摘要说明
    /// </summary>
    public class ValidateCode : IHttpHandler, System.Web.SessionState.IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "image/Jpeg";

            string validateCode = ValidateHelpers.CreateValidateCode();
            byte[] validateCodeBuffer = ValidateHelpers.CreateValidateImage(validateCode);

            context.Session.Add(nameof(Entity.ViewEntitys.LoginViewModel.validateCode), validateCode);
            context.Response.BinaryWrite(validateCodeBuffer);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}